package com.jxpanda.spring.module.auth.core.authentication.strategy;

import com.jxpanda.spring.module.auth.core.authentication.manager.CaptchaReactiveAuthenticationManager;
import com.jxpanda.spring.module.auth.core.authentication.manager.CollaborativeReactiveAuthenticationManager;
import com.jxpanda.spring.module.auth.core.authentication.manager.OAuth2UserDetailsRepositoryReactiveAuthenticationManager;
import com.jxpanda.spring.module.auth.core.authentication.manager.WechatMiniProgramReactiveAuthenticationManager;
import com.jxpanda.spring.module.auth.core.component.CaptchaReactiveService;
import com.jxpanda.spring.module.auth.core.user.OAuth2ReactiveUserDetailsRepository;
import com.jxpanda.spring.module.auth.endpoint.GrantType;
import reactor.core.publisher.Flux;


public class CaptchaCollaborativeReactiveAuthenticationStrategy extends AbstractCollaborativeReactiveAuthenticationStrategy {


    private final CaptchaReactiveAuthenticationManager captchaReactiveAuthenticationManager;

    private final OAuth2UserDetailsRepositoryReactiveAuthenticationManager oAuth2UserDetailsRepositoryReactiveAuthenticationManager;

    public CaptchaCollaborativeReactiveAuthenticationStrategy(CaptchaReactiveService captchaReactiveService, OAuth2ReactiveUserDetailsRepository oAuth2ReactiveUserDetailsRepository) {
        super(oAuth2ReactiveUserDetailsRepository);
        this.captchaReactiveAuthenticationManager = new CaptchaReactiveAuthenticationManager(captchaReactiveService);
        this.oAuth2UserDetailsRepositoryReactiveAuthenticationManager = new OAuth2UserDetailsRepositoryReactiveAuthenticationManager(oAuth2ReactiveUserDetailsRepository);
    }

    @Override
    public boolean isSupport(String grantType) {
        return GrantType.WECHAT_MINI_PROGRAM.getValue().equals(grantType);
    }

    @Override
    protected Flux<CollaborativeReactiveAuthenticationManager> getAuthenticationChain() {
        return Flux.just(captchaReactiveAuthenticationManager, oAuth2UserDetailsRepositoryReactiveAuthenticationManager);
    }

}
